package org.mq.mymq.broker.utils;

/**
 * @ClassName ByteConverUtil
 * @Description 字节数组转化工具
 * @Author jiarong_ye
 * @Date 2025/6/16 9:40
 * @Version 1.0
 */
public class ByteConverUtil {
    public static byte[] intToByteArray(int value) {
        byte[] result = new byte[4];
        result[3] = (byte) ((value >> 24) & 0xFF);
        result[2] = (byte) ((value >> 16) & 0xFF);
        result[1] = (byte) ((value >> 8) & 0xFF);
        result[0] = (byte) (value & 0xFF);
        return result;
    }
    public static int byteArrayToInt(byte[] array) {
        int value;
        value = (int) ((array[0] & 0xFF)
                | ((array[1] << 8) & 0xFF00)
                | ((array[2] << 16) & 0xFF0000)
                | ((array[3] << 24) & 0xFF000000));
        return value;
    }

    public static byte[] readInPos(byte[] source, int pos, int len) {
        byte[] result = new byte[len];
        System.arraycopy(source, pos, result, 0, len);
        return result;
    }

    public static void main(String[] args) {
    }
}
